from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By
# 专门用于模拟复杂的用户交互操作
from selenium.webdriver.common.action_chains import ActionChains

import time


# 设置浏览器、启动浏览器
def create_driver():
    options = Options()
    options.add_argument('--no-sandbox')
    options.add_experimental_option("detach", True)
    driver_edge = webdriver.Edge(options=options)
    return driver_edge
driver = create_driver()

driver.get("https://www.bilibili.com/")
# 找到需要悬停的元素
el_hover = driver.find_element(By.XPATH, '//*[@id="i_cecream"]/div[2]/div[1]/div[1]/ul[1]/li[6]/a/span')

# 执行悬停操作
    # actions = ActionChains(driver)  # 创建动作链对象
    # actions.操作1().操作2().操作3().perform()  # 链式调用，最后执行
actions = ActionChains(driver)
actions.move_to_element(el_hover).perform()
print("鼠标停在了漫画上")
time.sleep(1)
subel_hover = driver.find_element(By.XPATH, '//*[@id="i_cecream"]/div[2]/div[1]/div[1]/ul[1]/li[6]/div/div/div/div[2]/div[2]/div[1]')
actions.click(subel_hover).perform()
print("我已经点击了第一条链接")